'use strict';

(function () {

    /* Report Execution */
    var  executeReport = function (queryName, org, year, quarter) {

            var report = [
                    {kpiName: "n:Total number of scaled category over a period of time",
                        value: "78", groupID: "1"},
                    {kpiName: "nNI: Number of events rated Need Improvement (NI)",
                        value: "35", groupID: "1"},
                    {kpiName: "nS:   Number of events rated Satisfactory (S)",
                        value: "42", groupID: "1"},
                    {kpiName: "nO:   Number of events rated Outstanding (O)",
                        value: "36", groupID: "1"},
                    {kpiName: "# of training hours conducted",
                        value: "36", groupID: "2"},
                    {kpiName: "# of training hours with full utilization",
                        value: "36", groupID: "2"}

                ],

                groupsList = [
                    {id: '1', text: "Response Time"},
                    {id: '2', text: "Training Schedule Attainment"}
                ];

            var result = {'groupList': groupsList, 'reportData': report};
            return result;
        },

        varList = function (queryName) {
            var result = {
                "asx:abap": {
                    "asx:values": {
                        "VARIABLES": {
                            "item": {
                                "VARI_NAME": "X_WHNUMB",
                                "VARI_PAR_SEL": "S",
                                "VARI_TEXT": "Warehouse Number",
                                "ENTRY_TYPE": "0",
                                "DATA_TYPE": "CHAR",
                                "OUTPUT_LEN": "000003",
                                "ABAP_TYPE": "C",
                                "OBJ_NAME": "0WHSE_NUM",
                                "INT_LEN": "000003",
                                "P_DECIMALS": "000000",
                                "P_SIGN": "",
                                "CASE_SENSE": "",
                                "CHECK_BOX": "",
                                "LOWVAL": "",
                                "HIGHVAL": "",
                                "SIGN": "I",
                                "OPT": "EQ",
                                "DEF_VAL": "",
                                "VARTYP": "1"
                            }
                        }
                    }
                }
            }
            return result;
        },

        f4Help = function (iobjnm, vname, queryName) {
            var result = {
                "asx:abap": {
                    "asx:values": {
                        "F4VALUE": {
                            "item": [
                                {
                                    "CHAVL_INT": "SH_9999",
                                    "CHAVL_INT_NC": "SH_9999",
                                    "CHAVL_EXT": "SH_9999",
                                    "CHAVL_EXT_NC": "SH_9999",
                                    "CHATEXT": {
                                        "TXTSH": "SH_9999",
                                        "TXTMD": "SH_9999",
                                        "TXTLG": "SH_9999"
                                    }
                                },
                                {
                                    "CHAVL_INT": "SH_9999.0704",
                                    "CHAVL_INT_NC": "SH_9999.0704",
                                    "CHAVL_EXT": "SH_9999.0704",
                                    "CHAVL_EXT_NC": "SH_9999.0704",
                                    "CHATEXT": {
                                        "TXTSH": "SH_9999.0704",
                                        "TXTMD": "SH_9999.0704",
                                        "TXTLG": "SH_9999.0704"
                                    }
                                }
                            ]
                        }
                    }
                }
            }

            return result;
        },

        varInfo = function (varTechName){
            var result = {
                "asx:abap": {
                    "asx:values": {
                        "VARIABLES": {
                            "VARI_NAME": "X_WHNUMB",
                            "VARI_TEXT": "",
                            "VARI_TEXT_L": "Warehouse Number",
                            "VARI_PAR_SEL": "S",
                            "ENTRY_TYPE": "1",
                            "OBJ_NAME": "0WHSE_NUM"
                        }
                    }
                }
            }
            return result;
        },

        getAppSetting = function () {
            var yearList = ['2014', '2013', '2012', '2011'];
            var networkId = "darwmh0d";
            var fullName = "Mohammed Al-Darwish";
            var result = {'yearList': yearList, 'networkId': networkId, 'fullName': fullName};
            return result;
        }


    this.appVo = new AppVO();
    angular.module('memoryServices', [])
        .factory('Query', [
            function () {
                return {
                    executeQuery : function(queryName, param)
                    {
                        return $http({method: appVo.METHOD, url: appVo.BSP_QUERY_EXECUTE_URL, params: param});
                    },

                    getF4Help : function (iobjnm, vname, queryName) {
                        var param = {
                            iobjnm: iobjnm,
                            vname: vname,
                            queryName:queryName
                        };
                        return   $http({method: appVo.METHOD, url: appVo.BSP_GET_F4_URL , params: param});
                    },

                    getVarList : function(queryName) {
                        var param = {
                            rep_id: queryName
                        };
                        return  $http({method: appVo.METHOD, url: appVo.BSP_QUERY_VARS_LIST_URL, params: param});
                    },

                    getOrgTree : function(param)   {
                        var param = {};
                        return $http({method: appVo.METHOD, url: appVo.BSP_ORG_TREE_URL});
                    }
                }

            }])
        .factory('Employee', [
            function () {
                return {
                    query: function () {
                        return employees;
                    },
                    get: function (employee) {
                        return findById(parseInt(employee.employeeId));
                    }
                }

            }])
        .factory('Report', [
            function () {
                return {
                    query: function (queryName, org, year, quarter) {
                        return executeReport('ZAD_MAT_01', '99993122002', '2014', '1');
                    },
                    getVarList: function (queryName) {
                        return varList(queryName);
                    },

                    getVarInfo : function (varTechName) {
                        return varInfo(varTechName);
                    },
                    getF4Help : function (iobjnm, vname, queryName) {
                        return f4Help(iobjnm, vname, queryName);
                    }
                }

            }])

        .factory('AppSetting', [
            function () {
                return {
                    getSetting: function () {
                        return getAppSetting();
                    }
                }

            }])

        .factory('OrgTree', [
            function () {
                return {
                    query: function () {
                        return null;
                    }
                }
            }])

}());